﻿<UserControl x:Class="PrestoDashboard.Tabs.PingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="700">

    <UserControl.DataContext>
        <Binding Source="{StaticResource PingViewModel}"/>
    </UserControl.DataContext>

    <UserControl.Resources>
        <CollectionViewSource x:Key="PingViewSource" Source="{Binding ServerPingDtoList}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="ApplicationServer.Name"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Grid.RowSpan="4" VerticalAlignment="Center" HorizontalAlignment="Center"
                   FontSize="24" Visibility="{Binding ShowWaitCursor}" Panel.ZIndex="1"
                   Foreground="White">Loading...
        </TextBlock>
        
        <Button Grid.Row="0" Width="120" Content="Send Ping Request" Style="{StaticResource StandardButton}" Command="{Binding PingCommand}"/>

        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Label Style="{StaticResource StandardLabel}" Content="Ping request time: " VerticalAlignment="Center"/>
            <Label Style="{StaticResource StandardLabel}" Content="{Binding PingRequest.RequestTime}" Width="240" VerticalAlignment="Center" ContentStringFormat="G"/>
        </StackPanel>
        
        <DataGrid Grid.Row="2" AutoGenerateColumns="False" IsReadOnly="True" HeadersVisibility="Column"
                      ItemsSource="{Binding Source={StaticResource PingViewSource}}" CanUserSortColumns="True">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=ApplicationServer}" Header="Server" Width="220" SortMemberPath="ApplicationServer.Name"/>
                <DataGridTextColumn Binding="{Binding Path=ResponseTime}" Header="Response Time" Width="180"/>
                <DataGridTextColumn Binding="{Binding Path=Comment}" Header="Comment" Width="*"/>
            </DataGrid.Columns>
        </DataGrid>

        <Button Grid.Row="3" Content="Refresh" Style="{StaticResource StandardButton}" Command="{Binding RefreshCommand}"/>
        
    </Grid>
    
</UserControl>
